import { IPageInfo } from '../utils/page_info'
import service from '../utils/request'

export interface IUserInfo {
  subscribe: number | string
  openid: string
  nickname: string
  sex: number | string
  city: string
  country: string
  province: string
  language: string
  headimgurl: string
  subscribe_time: number
  unionid: string
  remark: string
  groupid: number
  tagid_list: ITag[] | string[]
  subscribe_scene: string
  qr_scene: number
  qr_scene_str: string
}

export const columns = [
  {
    align: 'left',
    label: '状态',
    prop: 'subscribe',
  },
  {
    align: 'left',
    label: 'ID',
    prop: 'openid',
  },
  {
    align: 'left',
    label: '昵称',
    prop: 'nickname',
  },
  {
    align: 'center',
    label: '性别',
    prop: 'sex',
  },
  {
    align: 'center',
    label: '省份',
    prop: 'province',
  },
  {
    align: 'center',
    label: '城市',
    prop: 'city',
  },
  {
    align: 'left',
    label: '标签',
    prop: 'tagid_list',
  },
]

// @Tags UserInfo
// @Summary 分页获取UserInfo列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query request.PageInfo true "分页获取UserInfo列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /UserInfo/getUserInfoList [get]
export const getUserInfoList = (params: { pageInfo: IPageInfo; userInfo: IUserInfo }) => {
  return service({
    url: '/v1/users',
    method: 'get',
    params,
  })
}

export interface ITag {
  tag_id: number
  name: string
  count: number
}

export const getTagInfoList = (params: { pageInfo: IPageInfo; tagInfo: ITag }) => {
  return service({
    url: '/v1/tags',
    method: 'get',
    params,
  })
}

// getUsersByTag 查询制定标签的用户
export const getUsersByTag = (tag_id: string) => {
  return service({
    url: '/v1/tags/' + tag_id,
    method: 'get',
  })
}

// createTag 创建标签
export const createTag = (tag_name: string) => {
  return service({
    url: '/v1/tags',
    method: 'post',
    data: { tag_name: tag_name },
  })
}

// deleteTag 删除标签
export const deleteTag = (tag_id: number) => {
  return service({
    url: '/v1/tags',
    method: 'delete',
    data: { tag_id: tag_id },
  })
}

// updateTag 更新标签名称
export const updateTag = (data: ITag) => {
  return service({
    url: '/v1/tags',
    method: 'put',
    data,
  })
}

// putUserToTag 添加用户到分组
export const putUserToTag = (tag_id: number, ids: string[]) => {
  return service({
    url: '/v1/tags/' + tag_id,
    method: 'put',
    // params,
    data: { ids: ids },
  })
}

// broadByTag 群发消息到标签组
export const broadByTag = (tag_id: number, broad_msg: string) => {
  console.log(tag_id, broad_msg)

  return service({
    url: '/v1/tags/' + tag_id,
    method: 'put',
    // params,
    data: { broad_msg: broad_msg },
  })
}
